package ts.group.webapp.market.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ts.group.webapp.market.dao.IProdDao;
import ts.group.webapp.market.model.TProductInfo;

import com.starit.common.dao.support.Pagination;
import com.starit.common.dao.support.PaginationRequest;

@Service
public class IProdService {
	
	@Autowired
	private IProdDao IProdDao;
	
	/*根据id查询产品*/
	public TProductInfo  getProdById( Long id){
		return IProdDao.get(id);
	}
	
	
	/*条件查询所有产品*/
	public Pagination<TProductInfo>  findAllForPage(PaginationRequest paginationRequest){
		return IProdDao.findPage(paginationRequest);
	}
	
	/*根据编号查询产品*/
	public List<TProductInfo> getProdByCode(String productCode){
		if(productCode == null){
			return new ArrayList<TProductInfo>(0);
		}
		return IProdDao.findByNamedParam("productCode", productCode);
	}
	
	/*新增产品*/
	public Long createProd(TProductInfo TProductInfo){
		return IProdDao.save(TProductInfo);
	}
	
	/*更新产品*/
	public void updateProd(TProductInfo TProductInfo){
		IProdDao.update(TProductInfo);
	}
	
	/*删除产品*/
	public void removeProd(Long prodId){
		IProdDao.delete(prodId);
	}
}
